/**
 * Copyright (c) 2005-2012 https://github.com/zhangkaitao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.aiwei.tdjk.serviceManager.serviceType.service;

import com.aiwei.tdjk.common.service.BaseService;
import com.aiwei.tdjk.serviceManager.serviceType.entity.ServiceType;
import com.aiwei.tdjk.serviceManager.serviceType.repository.ServiceTypeRepository;
import com.aiwei.tdjk.sys.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


@Service("ServiceTypeService")
public class ServiceTypeService extends BaseService<ServiceType, Long> {

    @Autowired
    private ServiceTypeRepository getServiceTypeRepository() {
        return (ServiceTypeRepository) baseRepository;
    }


    public ServiceType findByName(String name) {
        if(StringUtils.isEmpty(name)) {
            return null;
        }
        return getServiceTypeRepository().findByName(name);
    }


    private boolean maybeUsername(String username) {
        if (!username.matches(User.USERNAME_PATTERN)) {
            return false;
        }
        //如果用户名不在指定范围内也是错误的
        if (username.length() < User.USERNAME_MIN_LENGTH || username.length() > User.USERNAME_MAX_LENGTH) {
            return false;
        }

        return true;
    }

    private boolean maybeEmail(String username) {
        if (!username.matches(User.EMAIL_PATTERN)) {
            return false;
        }
        return true;
    }

    private boolean maybeMobilePhoneNumber(String username) {
        if (!username.matches(User.MOBILE_PHONE_NUMBER_PATTERN)) {
            return false;
        }
        return true;
    }





}
